[T4Scaffolding.Scaffolder(Description = "Creates a Restful Service Client using HttpClient")][CmdletBinding()]
param(        
    [parameter(Position = 0, Mandatory = $true, ValueFromPipelineByPropertyName = $true)][string]$ModelType,
	[string]$Project,
	[string]$CodeLanguage,
	[string[]]$TemplateFolders,
	[switch]$Force = $false
)

$foundModelType = Get-ProjectType $ModelType -Project $Project -BlockUi
if (!$foundModelType) { return }

$serviceClientName = $foundModelType.Name + "ServiceClient"

$primaryKey = Get-PrimaryKey $foundModelType.FullName -Project $Project -ErrorIfNotFound
if (!$primaryKey) { return }

$outputPath = Join-Path Services ($foundModelType.Name + "ServiceClient")

$defaultNamespace = (Get-Project $Project).Properties.Item("DefaultNamespace").Value
$namespace = [T4Scaffolding.Namespaces]::Normalize($defaultNamespace + "." + [System.IO.Path]::GetDirectoryName($outputPath).Replace([System.IO.Path]::DirectorySeparatorChar, "."))
$modelTypeNamespace = [T4Scaffolding.Namespaces]::GetNamespace($foundModelType.FullName)

Add-ProjectItemViaTemplate $outputPath -Template RestfulServiceClientTemplate `
	-Model @{ 
		Namespace = $namespace; 
		ModelType = [MarshalByRefObject]$foundModelType;
		ModelTypeNamespace = $modelTypeNamespace;
		ServiceClientName = $serviceClientName; 
		PrimaryKey = [string]$primaryKey;
	} `
	-SuccessMessage "Added RestfulServiceClient output at {0}" `
	-TemplateFolders $TemplateFolders -Project $Project -CodeLanguage $CodeLanguage -Force:$Force